﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CoreData;
using Helper;
using System.Reflection;
namespace SchoolManagementSystem.Forms.BusinessForm
{
    public partial class frmStudentReserve : DevExpress.XtraEditors.XtraForm
    {

        public frmStudentReserve()
        {
            InitializeComponent();
            LoadData();
        }



        void LoadData()
        {
            var model = RegisterService.RegisterServices.StudentService;
            var data = (IList<Student>)model.GetListStudentReserved();
            if(data==null)
                data=  new List<Student>();
            gridControl1.DataSource = data;
            gridControl1.RefreshDataSource();
            gridView1.ViewCaption = "Danh sách có " + gridView1.RowCount + " dòng";

            PropertyInfo[] propertyInfos;
            propertyInfos = new Student().GetType().GetProperties();

            foreach (PropertyInfo proInfo in propertyInfos)
            {
                AttributeCollection attributes = TypeDescriptor.GetProperties(new Student().GetType())[proInfo.Name].Attributes;

                DescriptionAttribute myAttribute =
                   (DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
                if (String.IsNullOrEmpty(myAttribute.Description))
                {
                    gridView1.Columns[proInfo.Name].Visible = false;
                }
                else
                {
                    gridView1.Columns[proInfo.Name].Caption = myAttribute.Description;
                    gridView1.Columns[proInfo.Name].OptionsColumn.AllowEdit = false;
                }
            
            }


            gridView1.Columns["ClassExt"].GroupIndex = 0;
            gridView1.Columns["ClassExt"].VisibleIndex = 2;
            gridView1.ExpandAllGroups();

        }

       
       

    }
}
